import asyncio
import json
from channels.generic.websocket import AsyncWebsocketConsumer

class HelloWorldConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        await self.accept()
        while True:
            await self.send(text_data="Hello World")
            await asyncio.sleep(10)

    async def disconnect(self, close_code):
        pass

    async def receive(self, text_data):
        pass

class EventConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        await self.channel_layer.group_add("events", self.channel_name)
        await self.accept()

    async def disconnect(self, close_code):
        await self.channel_layer.group_discard("events", self.channel_name)

    async def send_event(self, event):
        await self.send(text_data=json.dumps(event['event']))

